package outoforder.leetcode01;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author shhjiang_001
 * @create 2020-07-12 15:49
 */
public class MyStack {
    /** Initialize your data structure here. */
    Queue<Integer> q = new LinkedList<>();
    int top_elem = 0;
    public MyStack() {

    }

    /** Push element x onto stack. */
    public void push(int x) {
        q.offer(x);
        top_elem = x;
    }

    /** Removes the element on top of the stack and returns that element. */
    public int pop() {
        int size = q.size();
        while (size>2){
            q.offer(q.poll());
            size--;
        }
        top_elem = q.peek();
        q.offer(q.poll());
        return q.poll();
    }

    /** Get the top element. */
    public int top() {
        return top_elem;
    }

    /** Returns whether the stack is empty. */
    public boolean empty() {
        return q.isEmpty();
    }
}
